package helper.chart

import helper.base.TimeHelper
import helper.base.file.FromFileHelper.readDoubleListFromFile
import helper.chart.ChartHelper.LineChartHelper.drawLineChart
import helper.chart.ChartHelper.LineChartHelper.drawLinesChart
import org.junit.Test
import res.FileRes

internal class ChartHelperTest {
    @Test
    fun t_2023_1014_203321_() {
        val yData1 = listOf(1.0, 2.0, 3.0)
        val yData2 = listOf(2.0, 3.0, 4.0)
        val yDataList = listOf(yData1, yData2)

        drawLinesChart(
            yDataList = yDataList,
            ifShowYDouble = true,
            savedFileName = "${FileRes.out_chart_file}" + "/ChartTest" + "/t_${TimeHelper.getT4NowTimeString()}.png",
            showedFrameTitle = "Multiple Line Chart"
        )
    }

    @Test
    fun t_2023_1014_204642_() {
        val random = java.util.Random()

        // 创建一个包含50条曲线的数据列表
        val yDataList = mutableListOf<List<Double>>()
        for (i in 1..50) {
            val yData = mutableListOf<Double>()
            for (j in 1..100) {  // 每条曲线有100个点
                yData.add(random.nextDouble() * 10)  // 使用随机数生成数据
            }
            yDataList.add(yData)
        }

        // 调用 taskDrawMultipleLineChart 绘制多条曲线
        drawLinesChart(
            yDataList = yDataList,
            ifShowYDouble = false,  // 设置为 false，因为 50 条曲线的标签可能会很混乱
            savedFileName = "${FileRes.out_chart_file}" + "/ChartTest" + "/t_${TimeHelper.getT4NowTimeString()}.png",
            showedFrameTitle = "50 Line Chart",
            frameWidth = 1200,  // 设置图表宽度为 1200
            frameHeight = 800   // 设置图表高度为 800
        )
    }

    @Test
    fun t_2023_1014_210021_() {
        // 创建一个包含50条曲线的数据列表
        val yDataList = mutableListOf<List<Double>>()
        for (i in 1..50) {
            val yData = mutableListOf<Double>()
            for (j in 1..100) {  // 每条曲线有100个点
                val x = j.toDouble() / 10.0
                val y = Math.sin(x + i * 0.2)  // 使用正弦函数生成数据，通过改变相位（i * 0.2）来得到不同的曲线
                yData.add(y)
            }
            yDataList.add(yData)
        }

        // 调用 taskDrawMultipleLineChart 绘制多条曲线
        drawLinesChart(
            yDataList = yDataList,
            ifShowYDouble = false,  // 设置为 false，因为 50 条曲线的标签可能会很混乱
            savedFileName = "${FileRes.out_chart_file}" + "/ChartTest" + "/t_${TimeHelper.getT4NowTimeString()}.png",
            showedFrameTitle = "50 Line Chart",
            frameWidth = 1200,  // 设置图表宽度为 1200
            frameHeight = 800   // 设置图表高度为 800
        )
    }

    @Test
    fun t_2023_1015_192949_() {
        val aBaseDir = "out\\ChartHelperTest"
        val yData = readDoubleListFromFile("${aBaseDir}\\t1\\in\\chart_min.txt")
        drawLineChart(
            yData = yData,
            savedFileName = "${aBaseDir}\\t2\\out\\chart_min.png",
        )
    }
}